<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$return['diy']=$this->plugin_setting('diy');
$basic=plugin('jy_videoshop')->plugin_setting('basic');
$return['basic']=$basic;
$return['banner']=$basic['hdps'];
if($_RQ['op']=='main'){
	/*******main*******/
	//首页轮播图
	//首页推荐项目
	$return['groups']=pdo_getall('jy_xiuvote_groups',array('uniacid'=>$_SESSION['uniacid'],'isshow'=>1),'','id desc');
	$reply=pdo_getall('jy_xiuvote_reply',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1','starttime <'=>time(),'endtime >'=>time()),'','paixu asc');
	$return['notices']=pdo_getall('core_account_article',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1'),'','id asc');

	if($reply){
		foreach($reply as &$r){
			$r['onum']=pdo_count('jy_xiuvote_opus',array('uniacid'=>$_SESSION['uniacid'],'rid'=>$r['id'],'status'=>1,'isshow'=>1));
			$r['starttime']=date('Y-m-d h:m:s',$r['starttime']);
		}
	}
	$return['reply']=$reply;
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'isshow'=>1);
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
			$return['params']['id']=intval($_RQ['keyword']);
		}else{
			$params['title like']='%'.$_RQ['keyword'].'%';
			$return['params']['title']=$_RQ['keyword'];
		}
	}
	//按点赞数排序作品
	$pindex = max(1, intval($_RQ['page']));
	$psize = 38;
	$total='';
	$list=pdo_getslice('jy_xiuvote_opus',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$sum=0;
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$reply=pdo_get('jy_xiuvote_reply',array('id'=>$item['rid'],'uniacid'=>$_SESSION['uniacid']));
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['reply']=$reply;
			$item['opus_images']=json_decode($item['opus_images'],true);
			$item['picsnum']=count($item['opus_images']);
			$item['votenums']=pdo_count('jy_xiuvote_votelog',array('oid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
			$item['group']=pdo_get('jy_xiuvote_groups',array('uniacid'=>$_SESSION['uniacid'],'id'=>$reply['groupid']));
			$jifen=pdo_getsum('jy_xiuvote_sendlplog',array('oid'=>$item['id'],'uniacid'=>$_SESSION['uniacid'],'status'=>1),'jifen');
			$item['votenums']=$item['votenums']+$jifen;
			$item['likes']=$item['likes']+$jifen;
		}
		//	print_r(count($list).'fff');exit;
		foreach($list as $key=>$value){
			if($value['reply']['endtime']*1000<time()){
			
				unset($list[$key]);
			}
		}
		//print_r(count($list).'fff');exit;
	}
	
	$return['list']=$list;
	set_html('title',$basic['title']?'首页-'.$basic['title']:'首页');
	$return['sharedata']=array(
		'title'=>$basic['share_title'],
		'desc'=>$basic['share_desc'],
		'link'=>custom_url('jy_videoshop/index/',true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	$return['params']=array();
	$return['msg'] = pdo_count('jy_xiuvote_notice_log', array('uid'=>$uid,'isread'=>0,'type'=>$type),'id');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1,'isshow'=>1);
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
			$return['params']['id']=intval($_RQ['keyword']);
		}else{
			$params['title like']='%'.$_RQ['keyword'].'%';
			$return['params']['title']=$_RQ['keyword'];
		}
	}
		
	//按点赞数排序作品
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_xiuvote_opus',$params,array($pindex,$psize),$total,$fields,'','likes desc, id desc');
	$return['likes']=pdo_getsum('jy_xiuvote_opus',array('status'=>1),'likes');
	$return['look']=pdo_getsum('jy_xiuvote_opus',array('status'=>1),'look');
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$reply=pdo_get('jy_xiuvote_reply',array('id'=>$item['rid'],'uniacid'=>$_SESSION['uniacid']));
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['reply']=$reply;
			$item['opus_images']=json_decode($item['opus_images'],true);
			$item['picsnum']=count($item['opus_images']);
			$item['thumb']=tomedia($item['thumb']);
			$item['votenums']=pdo_count('jy_xiuvote_votelog',array('oid'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
			$item['group']=pdo_get('jy_xiuvote_groups',array('uniacid'=>$_SESSION['uniacid'],'id'=>$reply['groupid']));
			$jifen=pdo_getsum('jy_xiuvote_sendlplog',array('oid'=>$item['id'],'uniacid'=>$_SESSION['uniacid'],'status'=>1),'jifen');
			$item['votenums']=$item['votenums']+$jifen;
			$item['likes']=$item['likes']+$jifen;
			$nickname=pdo_getcolumn('core_members',array('id'=>$item['mid'],'uniacid'=>$_SESSION['uniacid']),'nickname');
			$item['realname']=$item['realname']?$item['realname']:$nickname;
		}
	}
	$return['list']=$list;
	$return['params']['page'] =$pindex;
	$return['reply']=$reply;
	$return['intDiff']=$reply['endtime']- time();
	$return['endstatus']= $reply['endtime'] < time()? 2 : $reply['starttime'] <time()?1:0;
	$return['apstatus']= $reply['apendtime'] < time()? 2 : $reply['apstarttime'] <time()?1:0;
	exi($return);
}